package com.swinw.asumall.search.controller;

import com.swinw.asumall.search.service.SearchService;
import com.swinw.asumall.search.vo.SearchResult;
import com.swinw.asumall.search.vo.SearchVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class SearchController {

    @Autowired
    private SearchService searchService;

    @GetMapping("/list.html")
    public String searchHtml(SearchVo searchVo, Model model){
        String sort = searchVo.getSort();
        if(!StringUtils.isEmpty(sort)){
            model.addAttribute("sort",sort);
        }
        SearchResult result = searchService.search(searchVo);
        System.out.println("查询结果  " + result);
        model.addAttribute("result",result);
        return "list";
    }

}
